package org.example.sportdemo.service;

import org.example.sportdemo.entity.CompetitionCollection;
import org.example.sportdemo.entity.GroundCollection;
import org.example.sportdemo.mapper.CompetitionCollectionMapper;
import org.example.sportdemo.mapper.GroundCollectionMapper;
import org.example.sportdemo.utils.PageUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;
import java.util.Map;

@Service
public class CompetitionCollectionService {

    @Autowired
    private CompetitionCollectionMapper competitionCollectionMapper;

    public List<CompetitionCollection> selectAll(){
        return competitionCollectionMapper.selectAll();
    }

    public PageUtils queryPage(Map<String, Object> params) {
        //总数据
        List<CompetitionCollection> groundList = competitionCollectionMapper.selectAll();
        //总条数
        Integer totalCount = competitionCollectionMapper.selectCount();
        //当前页
        Integer currPage = Integer.valueOf((String) params.get("currPage"));
        //每页条数
        Integer pageSize = Integer.valueOf((String) params.get("pageSize"));
        return new PageUtils(totalCount,(Integer) pageSize,currPage,groundList);
    }

    public void addCompetitionCollection(CompetitionCollection competitionCollection) {

        Date date = new Date();
        competitionCollection.setCreate_time(date);
        competitionCollectionMapper.addCompetitionCollection(competitionCollection);

    }

    public CompetitionCollection selectById(Integer id) {
        return competitionCollectionMapper.selectById(id);
    }

    public void updateCompetitionCollection(CompetitionCollection competitionCollection) {
        competitionCollectionMapper.updateCompetitionCollection(competitionCollection);
    }

    public void deleteByIds(Integer[] ids) {
        competitionCollectionMapper.deleteByIds(ids);
    }
}
